import sys
from PyQt5.QtWidgets import QApplication, QWidget,QPushButton,QHBoxLayout,QVBoxLayout,QLineEdit,QGridLayout,QStackedWidget,QStackedLayout,QLabel
from untitled import Ui_MainWindow  # 替换为实际文件名

from PyQt5.QtCore import pyqtSignal

# class MainWindow(QMainWindow, Ui_MainWindow):
#     def __init__(self):
#         super().__init__()
#         self.setupUi(self)  # 自动加载UI布局

"""
class MyWindow(QWidget):
    def __init__(self):
        super().__init__()
        self.ui_show()

    def ui_show(self):
        self.setWindowTitle("hello world")

        layout = QVBoxLayout()

        edit = QLineEdit()
        edit.setText("nihaoya")

        layout.addWidget(edit)

        gridlayout = QGridLayout()

        bt1= QPushButton()
        bt1.setText("1")

        bt2= QPushButton()
        bt2.setText("2")

        bt3= QPushButton()
        bt3.setText("3")

        gridlayout.addWidget(bt1,0,0)
        gridlayout.addWidget(bt2,0,1)
        gridlayout.addWidget(bt3,0,2)

        bt4= QPushButton()
        bt4.setText("4")

        bt5= QPushButton()
        bt5.setText("5")

        bt6= QPushButton()
        bt6.setText("6")

        gridlayout.addWidget(bt4,2,0)
        gridlayout.addWidget(bt5,2,1)
        gridlayout.addWidget(bt6,3,2)

        layout.addLayout(gridlayout)


        self.setLayout(layout)


class Window1(QWidget):
    def __init__(self):
        super().__init__()
        label1 = QLabel("hello world1",self)
        label1.setStyleSheet("background-color: red;")

class Window2(QWidget):
    def __init__(self):
        super().__init__()
        label = QLabel("hello world2",self)
        label.setStyleSheet("background-color: green;")


class MyTestWindow(QWidget):
    def __init__(self):
        super().__init__()
        self.ui_init()

    def ui_init(self):
        self.setFixedSize(600,400)
        self.creatStackWindow()

        h_layout = QVBoxLayout()
        bt1 = QPushButton("界面1")
        bt2 = QPushButton("界面2")
        bt1.clicked.connect(self.bt_bt1_clicked)
        bt2.clicked.connect(self.bt_bt2_clicked)

        win = QWidget()
        win.setLayout(self.stack_layout)
        win.setStyleSheet("background-color: gray;")

        h_layout.addWidget(win)
        h_layout.addWidget(bt1)
        h_layout.addWidget(bt2)

        self.setLayout(h_layout)

    def bt_bt1_clicked(self):
        self.stack_layout.setCurrentIndex(0)

    def bt_bt2_clicked(self):
        self.stack_layout.setCurrentIndex(1)

    def creatStackWindow(self):
        self.stack_layout = QStackedLayout()
        win1 = Window1()
        win2 = Window2()
        self.stack_layout.addWidget(win1)
        self.stack_layout.addWidget(win2)

"""

class Slot_Test(QWidget):
    m_signal = pyqtSignal(str)
    def __init__(self):
        super().__init__()
        self.ui_init()

    def ui_init(self):
        btn = QPushButton("点击",self)
        btn.clicked.connect(self.bt_btn_clicked)

        self.m_signal.connect(self.m_bt_btn_clicked)

    def bt_btn_clicked(self):
        self.m_signal.emit("6666")

    def m_bt_btn_clicked(self,str):
        print(str)


if __name__ == "__main__":
    app = QApplication(sys.argv)
    w = Slot_Test()
    w.show()

    sys.exit(app.exec_())


